package com.qiuyang.service.show.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qiuyang.mapper.show.ShowBlogMapper;
import com.qiuyang.pojo.Blog;
import com.qiuyang.service.show.ShowBlogService;
import com.qiuyang.utils.MarkDownUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ShowBlogServiceImpl implements ShowBlogService {

    @Autowired
    private ShowBlogMapper showBlogMapper;

    @Override
    public int countBlog() {
        return showBlogMapper.countBlog();
    }

    @Override
    public List<Blog> findAllBlog() {
        return showBlogMapper.findAllBlog();
    }

    @Override
    public List<Blog> blogRecommed() {
        return showBlogMapper.blogRecommed();
    }

    @Override
    public Blog showBlog(Long id) {
        Blog blog = showBlogMapper.showBlog(id);
        blog.setContext(MarkDownUtils.markdownToHtmlExtensions(blog.getContext()));
        return blog;
    }

    @Override
    public void insertViews(Long id) {
        showBlogMapper.insertViews(id);
    }

    @Override
    public PageInfo<Blog> findBlogAndList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Blog> pageInfo = new PageInfo<>(showBlogMapper.findAllBlog());
//        Map<String,Object> map = new HashMap<>();
//        map.put("list",new PageInfo<>(showBlogMapper.findAllBlog()));
////        map.put("list",pageInfo.getList());
//        map.put("total",pageInfo.getTotal());
        return pageInfo;
    }

    @Override
    public PageInfo<Blog> findBlogTitle(String title, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Blog> blogTitle = new PageInfo<>(showBlogMapper.findBlogTitle(title));
        return blogTitle;
    }


}
